package jmine.tec.aom.pack;

import jmine.tec.aom.domain.PropertyGroup;
import jmine.tec.database.pack.populator.AbstractPopulatorDataSource;
import jmine.tec.database.pack.populator.PopulatorBean;
import jmine.tec.utils.collection.Mapper;
import jmine.tec.utils.collection.MapperUtils;
import bancosys.tec.persist.dao.BaseDAO;

/**
 * Pack populator for property groups
 * 
 * @author lundberg
 */
public class PropertiesPopulatorDataSource extends AbstractPopulatorDataSource<PropertyGroup> {

    private BaseDAO<PropertyGroup> propertyGroupDAO;

    /**
     * {@inheritDoc}
     */
    public Iterable<PopulatorBean<PropertyGroup>> load() {
        return MapperUtils.mapList(this.propertyGroupDAO.findAllOrderedByPk(), new Mapper<PropertyGroup, PopulatorBean<PropertyGroup>>() {
            public PopulatorBean<PropertyGroup> apply(PropertyGroup input) {
                return new PopulatorBean<PropertyGroup>(input, "properties", input.getMnemonic().toLowerCase() + ".xml");
            }
        });
    }

    /**
     * @param propertyGroupDAO the propertyGroupDAO to set
     */
    public void setPropertyGroupDAO(BaseDAO<PropertyGroup> propertyGroupDAO) {
        this.propertyGroupDAO = propertyGroupDAO;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "PropertiesPopulatorDataSource";
    }
}
